package com.linln.modules.userule.rule;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.linln.modules.ticket.domain.Ticket;
import com.linln.modules.ticket.rule.Rule;
import com.linln.modules.ticket.rule.RuleResult;
import com.linln.modules.ticket.domain.TicketLog;
import com.linln.modules.ticket.service.TicketLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.common.rules
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.common.rules
 * @Description: TODO
 * @date Date : 2020年11月25日 16:26
 */
//自然月规则
@Component
@Order(Integer.MIN_VALUE)
public class NaturalMonthRule implements Rule {
    @Autowired
    private TicketLogService ticketLogService;

    @Override
    public boolean support(String ruleName) {
        return RuleConstant.NATURALMONTHRULE.equals(ruleName);
    }

    @Override
    public RuleResult handlerCode(String userId, Ticket ticket,String shopId) {
        QueryWrapper<TicketLog> queryWrapper = new QueryWrapper<>();
        List<TicketLog> ticketLogs = ticketLogService.getCurrentMonthTicketLog(ticket.getTicketCode());
        if (ticketLogs != null && ticketLogs.size() > 0) {
            return RuleResult.error("本月已使用,请下月再使用");
        }
        return RuleResult.ok("可以使用");
    }
}
